#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include "testutils.h"

/*
 * +4 cards
 * +1 buy
 * Each other player draws 1 card
 */
void test_council_room() 
{
	int i, j, k;
	int fail_count = 0;
	int prev_buys;
	struct gameState state;
	int num_players = 4;

	init_test_data(&state, num_players);

	srand(time(NULL));

	for (i = 0; i < MAX_ITERATIONS; ++i) {
		for (j = 0; j < num_players; j++) {
			state.deckCount[j] = 50;
			for (k = 0; k < state.deckCount[j]; k++) {
				state.deck[j][k] = random_card();
			}

			state.handCount[j] = 5;
		}

		for (j = 0; j < 4; j++) {
			state.hand[0] = random_card();
		}
		state.hand[0][4] = council_room;

		prev_buys = state.numBuys;

		council_room_effect(0, &state, 4);

		if (state.numBuys <= prev_buys) {
			printf("ERROR: iteration %d.  numBuys not incremented.\n", i);
		}

		if (state.handCount[0] <= 9) {
			printf("ERROR: iteration %d.  handCount not updated.\n", i);
		}

		for (j = 1; j < num_players; j++) {
			if (state.handCount[i] <= 5) {
				printf("ERROR: iteration %d.  Other player %d did not have handCount updated.\n", i, j);
			}
		}
	}

	if (fail_count > 0)	{
		printf("Test failed!  Number of random test failures: %d\n", fail_count);
	} else {
		printf("All random tests passed!\n");
	}
}

int main(void)
{
	test_council_room();
	return 0;
}